import java.util.Scanner;

public class Triangle {
    double length1 = 0;
    double length2 = 0;
    double length3 = 0;

    public Triangle(double a, double b, double c) {
        this.length1 = a;
        this.length2 = b;
        this.length3 = c;
        //用递归判断是否能构成三角形 或者 重新设置长度
        if (judge(a, b, c)) {
            reSet();
        }
    }

    /**
     * 判断三边是否能构造成三角形 不可以返回true
     * @param a
     * @param b
     * @param c
     * @return result
     */
    private boolean judge(double a, double b, double c) {
        boolean result = false;
        if ((a + b) <= c || (a + c) <= b || (b + c) <= a)
            result = true;
        return result;
    }

    /**
     * 重新设置三角形的三条边
     */
    private void reSet() {
        System.out.println("三边无法构建出三角形,请重新设置：");
        Scanner scanner = new Scanner(System.in);
        this.length1 = scanner.nextInt();
        this.length2 = scanner.nextInt();
        this.length3 = scanner.nextInt();
        if (judge(this.length1, this.length2, this.length3))
            reSet();
    }

    public double getPerimeter() {
        return length1 + length3 +length2;
    }


    /**
     * 海伦公式计算三角形面积
     * @return result;
     */
    public double getArea() {
        double result = 0;
        double p = (length1 + length2 + length3) / 2;
        result = Math.sqrt(p * (p-length1) * (p-length2) * (p-length3));
        return result;
    }
}
